/* eslint-disable no-return-assign */
/* eslint-disable default-param-last */
/* eslint-disable jsx-a11y/label-has-associated-control */
/* eslint-disable react/no-unstable-nested-components */
/* eslint-disable no-shadow */
/* eslint-disable no-debugger */
/* eslint-disable react/no-array-index-key */

/**
 * 常规表单布局结构
 * @Author Lianqi
 * @Date 2022-7-8
 * @description
 *  适应表单layout属性为：
 *  VERTICAL: 'vertical', // 单列垂直布局
 *  HORIZONAL: 'horizonal', // 单列水平布局
 *  INLINE: 'inline', // 行内布局
 */

import { Form } from 'antd'
import FieldControl from './formitem/FieldControl'
import FieldText from './formitem/FieldText'
import { FIELD_MODE, MODE, ControlType as TYPE } from '../config/Constant'
import NumberRange from './formitem/NumberRange'

function FormLayoutAntd(props) {
  const { mode: formMode = MODE.EDIT, fieldList, ...restProps } = props

  return (
    <>
      {fieldList?.map(
        ({
          key,
          name,
          label,
          mode: fieldMode = FIELD_MODE.EDIT,
          formitemprops,
          controlProps,
          controlType,
          textFieldName,
          text,
        }) => (
          // fieldMode !== FIELD_MODE.HIDDEN ? (
          //   <Form.Item key={key} label={label} {...formitemprops}>
          //     {formMode === MODE.READONLY || fieldMode === FIELD_MODE.READONLY ? (
          //       <FieldText {...controlProps} withText={textFieldName} text={text} />
          //     ) : (
          //       <FieldControl
          //         disabled={formMode === MODE.DISABLED || fieldMode === FIELD_MODE.DISABLED}
          //         {...controlProps}
          //         {...restProps}
          //       />
          //     )}
          //   </Form.Item>
          // ) : null
          <Form.Item
            key={key}
            name={name}
            label={label}
            hidden={fieldMode === FIELD_MODE.HIDDEN}
            {...formitemprops}
          >
            {formMode === MODE.READONLY || fieldMode === FIELD_MODE.READONLY ? (
              <FieldText {...controlProps} withText={textFieldName} text={text} />
            ) : (
              controlType === TYPE.INPUT_NUMBER_RANGE ? (<NumberRange />) :
              (
                <FieldControl
                  disabled={formMode === MODE.DISABLED || fieldMode === FIELD_MODE.DISABLED}
                  {...controlProps}
                  {...restProps}
                />
              )
            )}
          </Form.Item>
        )
      )}
    </>
  )
}

export default FormLayoutAntd
